package com.woniuxy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.mapper.UserBanMapper;
import com.woniuxy.pojo.User;
import com.woniuxy.pojo.UserBan;
import com.woniuxy.service.UserBanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Administrator
* @description 针对表【t_user_ban】的数据库操作Service实现
* @createDate 2025-06-11 16:37:32
*/
@Service
public class UserBanServiceImpl extends ServiceImpl<UserBanMapper, UserBan>
    implements UserBanService {

    @Autowired
    UserBanMapper userBanMapper;

    @Autowired
    UserServiceImpl userService;

    @Override
    public Boolean cancelBan(Long id) {
        //根据id查询出改封禁信息，
        UserBan userBan = userBanMapper.selectById(id);
        //修改该条记录的状态，为0表示解封了，与用户表同一
        userBan.setStatus(1);
        int i = userBanMapper.updateById(userBan);
        //同步更新用户表中的用户状态码e
        User user = userService.getById(userBan.getUserId());
        if(user != null) user.setStatus(1);
        return i>0;
    }

    @Override
    public Boolean batchCancel(List<Long> ids) {
        return ids.stream()
                .map(this::cancelBan)// 对每个 id 调用已有方法
                .allMatch(Boolean::booleanValue);// 判断是否全部成功
    }

    @Override
    public Boolean banRemPreUser(List<Integer> ids) {
        return null;
    }
}




